﻿'
'* Copyright (c) 2007-2009 SlimDX Group
'* 
'* Permission is hereby granted, free of charge, to any person obtaining a copy
'* of this software and associated documentation files (the "Software"), to deal
'* in the Software without restriction, including without limitation the rights
'* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
'* copies of the Software, and to permit persons to whom the Software is
'* furnished to do so, subject to the following conditions:
'* 
'* The above copyright notice and this permission notice shall be included in
'* all copies or substantial portions of the Software.
'* 
'* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
'* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
'* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
'* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
'* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
'* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
'* THE SOFTWARE.
'

Imports System
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports SlimDX
Imports SlimDX.Direct3D9



'  Represents a single transformed, colored, and textured vertex.

<StructLayout(LayoutKind.Sequential)> _
Public Structure TransformedColoredTexturedVertex
    Implements IEquatable(Of TransformedColoredTexturedVertex)
    Private m_Position As Vector4
    Private m_TextureCoordinates As Vector2
    Private m_Color As Integer
    Private m_Normal As Vector3


    Public Shared Function VertexDescriptor() As VertexElement()
        ' Position: DeclarationType.Float4, DeclarationUsage.PositionTransformed
        ' Color:    DeclarationType.Color, DeclarationUsage.Color
        ' Texture:  DeclarationType.Float2, DeclarationUsage.TextureCoordinate
        ' normal:  DeclarationType.Float3, DeclarationUsage.Normal
        'New VertexElement(0, 12, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0), _
        Return {New VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0), _
                               New VertexElement(0, 12, DeclarationType.Float2, DeclarationMethod.Default, DeclarationUsage.TextureCoordinate, 0), _
                               New VertexElement(0, 24, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0), _
                               New VertexElement(0, 36, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Normal, 0), _
                               New VertexElement(0, 48, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Tangent, 0), _
                               New VertexElement(0, 60, DeclarationType.Float3, DeclarationMethod.Default, DeclarationUsage.Binormal, 0), _
                                                          VertexElement.VertexDeclarationEnd}
    End Function


    'Public Property Normal() As Vector3
    '    Get
    '        Return m_Normal
    '    End Get
    '    Set(ByVal value As Vector3)
    '        m_Normal = value
    '    End Set
    'End Property
    ' Gets or sets the transformed position of the vertex.
    ' The transformed position of the vertex. 
    ' <VertexElement(DeclarationType.Float4, DeclarationUsage.PositionTransformed)> _
    Public Property Position() As Vector4
        Get
            Return m_Position
        End Get
        Set(ByVal value As Vector4)
            m_Position = value
        End Set
    End Property


    '  Gets or sets the color of the vertex.
    ' <VertexElement(DeclarationType.Color, DeclarationUsage.Color)> _
    Public Property Color() As Integer
        Get
            Return m_Color
        End Get
        Set(ByVal value As Integer)
            m_Color = value
        End Set
    End Property


    ' <VertexElement(DeclarationType.Float2, DeclarationUsage.TextureCoordinate)> _

    Public Property TextureCoordinates() As Vector2
        Get
            Return m_TextureCoordinates
        End Get
        Set(ByVal value As Vector2)
            m_TextureCoordinates = value
        End Set
    End Property

    ''' <summary>
    ''' Gets the size in bytes.
    ''' </summary>
    ''' <value>The size in bytes.</value>
    Public Shared ReadOnly Property SizeInBytes() As Integer
        Get
            Return Marshal.SizeOf(GetType(TransformedColoredTexturedVertex))
        End Get
    End Property

    ''' <summary>
    ''' Gets the format.
    ''' </summary>
    ''' <value>The format.</value>
    Public Shared ReadOnly Property Format() As VertexFormat
        Get
            Return VertexFormat.Texture1 Or VertexFormat.Diffuse Or VertexFormat.Position Or VertexFormat.Normal  'VertexFormat.Position Or VertexFormat.Diffuse Or VertexFormat.Texture1 Or VertexFormat.PositionW Or VertexFormat.Normal
        End Get
    End Property

    ''' <summary>
    ''' Initializes a new instance of the <see cref="TransformedColoredTexturedVertex"/> struct.
    ''' </summary>
    ''' <param name="position">The position.</param>
    ''' <param name="color">The color.</param>
    ''' <param name="textureCoordinates">The texture coordinates.</param>
    Public Sub New(ByVal position As Vector4, ByVal color As Integer, ByVal textureCoordinates As Vector2)

        Me.Position = position
        Me.Color = color
        Me.TextureCoordinates = textureCoordinates
        Me.m_Normal = New Vector3(0, 0, 0)
    End Sub

    ''' <summary>
    ''' Implements the operator ==.
    ''' </summary>
    ''' <param name="left">The left side of the operator.</param>
    ''' <param name="right">The right side of the operator.</param>
    ''' <returns>The result of the operator.</returns>
    Public Shared Operator =(ByVal left As TransformedColoredTexturedVertex, ByVal right As TransformedColoredTexturedVertex) As Boolean
        Return left.Equals(right)
    End Operator

    ''' <summary>
    ''' Implements the operator !=.
    ''' </summary>
    ''' <param name="left">The left side of the operator.</param>
    ''' <param name="right">The right side of the operator.</param>
    ''' <returns>The result of the operator.</returns>
    Public Shared Operator <>(ByVal left As TransformedColoredTexturedVertex, ByVal right As TransformedColoredTexturedVertex) As Boolean
        Return Not (left = right)
    End Operator

    ''' <summary>
    ''' Returns the hash code for this instance.
    ''' </summary>
    ''' <returns>
    ''' A 32-bit signed integer that is the hash code for this instance.
    ''' </returns>
    Public Overrides Function GetHashCode() As Integer
        Return Position.GetHashCode() + Color.GetHashCode() + TextureCoordinates.GetHashCode()
    End Function

    ''' <summary>
    ''' Indicates whether this instance and a specified object are equal.
    ''' </summary>
    ''' <param name="obj">Another object to compare to.</param>
    ''' <returns>
    ''' true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
    ''' </returns>
    Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean
        If obj Is Nothing Then
            Return False
        End If

        If Me.GetType() IsNot obj.GetType() Then
            Return False
        End If

        Return Equals(CType(obj, TransformedColoredTexturedVertex))
    End Function

    ''' <summary>
    ''' Indicates whether the current object is equal to another object of the same type.
    ''' </summary>
    ''' <param name="other">An object to compare with this object.</param>
    ''' <returns>
    ''' true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
    ''' </returns>
    Public Overloads Function Equals(ByVal other As TransformedColoredTexturedVertex) As Boolean Implements IEquatable(Of TransformedColoredTexturedVertex).Equals
        Return (Position = other.Position AndAlso Color = other.Color AndAlso TextureCoordinates = other.TextureCoordinates)
    End Function

    ''' <summary>
    ''' Returns a string representation of the current object.
    ''' </summary>
    ''' <returns>
    ''' A <see cref="T:System.String"/> representing the vertex.
    ''' </returns>
    Public Overrides Function ToString() As String
        Return String.Format(CultureInfo.CurrentCulture, "{0} ({1}, {2})", Position.ToString(), System.Drawing.Color.FromArgb(Color).ToString(), TextureCoordinates.ToString())
    End Function


    ''' <summary>
    ''' Returns vector3 from PotitionRhW
    ''' </summary>
    ''' <returns>
    ''' A <see cref="T:System.String"/> representing the vertex.
    ''' </returns>
    Public Function ToVector3() As Vector3
        Return New Vector3(Position.X, Position.Y, Position.Z)
    End Function


End Structure

' mio
Public Structure Primitiva
    Public Name As String
    Public Enabled As Boolean
    Public Stream As DataStream
    Public VertBuff As VertexBuffer
    Public IndexBuff As IndexBuffer
    Public Verticies() As TransformedColoredTexturedVertex
    Public Faces As Integer
    Public dr As DataRectangle
End Structure